/**
 * 
 */
package org.go2sh.AndroMail.Mail;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * @author Christoph
 *
 */
public class Pop {
	private String 	Username;
	private String 	Password;
	private int		Port;
	private	String	Hostname;
	private boolean Connected;
	private boolean LoggedIn;
	
	private Socket 	socket;
	private OutputStream out;
	private InputStream in;
	
	public Pop() {
		super();
	}
	public void Connect(String Username,String Password,String Hostname,int Port) throws MailException {
		try {
			this.socket = new Socket(Hostname,Port);
			this.out = this.socket.getOutputStream();
			this.in = this.socket.getInputStream();
			byte buf[] = new byte[4096];
			int len;
			while ((len = this.in.read(buf))>0) {
				String Message = new String(buf,0,len);
				PopAnswerChecker check = new PopAnswerChecker(Message);
				if (check.isOK()) {
					this.Connected = true;
				} else {
					throw new MailException("Pop Server ("+this.Hostname+":"+(new Integer(this.Port)).toString()+") is not ready.");
				}
			}
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}

}
